-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: add edit_and_execute composite tool #7608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add new tool that combines file editing operations with command execution - Supports write_to_file, apply_diff, insert_content, and search_and_replace as edit operations - Executes command only if edit operation succeeds - Add comprehensive tests for the new tool - Update type definitions and tool registry Implements #7607
| import { Task } from "../task/Task" | ||
| import { ToolUse, AskApproval, HandleError, PushToolResult, RemoveClosingTag } from "../../shared/tools" | ||
| import { formatResponse } from "../prompts/responses" | ||
| import { ClineSayTool } from "../../shared/ExtensionMessage" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the unused import 'ClineSayTool' to keep the module clean.
| import { ClineSayTool } from "../../shared/ExtensionMessage" |
| if (block.partial) { | ||
| // For partial blocks, show progress | ||
| const partialMessage = { | ||
| tool: "editAndExecute" as const, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, use the tool name 'edit_and_execute' instead of 'editAndExecute' in the partial message.
| tool: "editAndExecute" as const, | |
| tool: "edit_and_execute" as const, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote this code and now I'm reviewing it. Trust issues: maximum.
Review Findings
Critical Issues (Must Fix):
-
Missing checkpoint save before edit operations (
src/core/tools/editAndExecuteTool.ts)- The tool doesn't call
checkpointSaveAndMarkbefore performing edit operations - All other edit tools in the codebase call this before modifications to ensure data safety
- Should add
await checkpointSaveAndMark(cline)before delegating to edit tools - Also missing in
presentAssistantMessage.tsbefore callingeditAndExecuteTool
- The tool doesn't call
-
Incomplete test coverage (
src/core/tools/__tests__/editAndExecuteTool.spec.ts)- Tests only cover error cases (missing args, missing blocks, partial blocks)
- Missing tests for successful execution paths with different edit tools
- Should add tests for successful write_to_file, apply_diff, insert_content, search_and_replace + execute_command combinations
Important Suggestions:
-
Error handling inconsistency (
src/core/tools/editAndExecuteTool.tsline ~232)- When edit operation fails, only shows generic "Edit operation failed" message
- Should capture and include the actual error from the edit tool for better debugging
-
Parameter validation (
src/shared/tools.ts)- Confirmed
argsparameter is correctly kept in toolParamNames array - Used by both
edit_and_executeand multi-fileapply_diff
- Confirmed
Minor Improvements:
-
Code duplication (
src/core/tools/editAndExecuteTool.ts)- Repetitive XML parsing logic could be extracted into a helper function
- Would reduce duplication and improve maintainability
-
Documentation
- While main function has good JSDoc, individual switch cases could benefit from inline comments
Overall, the implementation follows the requirements from issue #7607 well, but needs these critical fixes before merging.
|
Closing, see #7607 (comment) |
This PR implements the
edit_and_executecomposite tool as requested in #7607.Summary
Adds a new composite tool that combines file editing operations with command execution in a single atomic operation. This addresses the inefficiency of making two separate tool calls for common development tasks.
Changes
edit_and_executeto the tool type definitions inpackages/types/src/tool.tssrc/core/tools/editAndExecuteTool.tssrc/shared/tools.ts(display names, groups, parameter names)Implementation Details
The tool:
<edit>and<execute>blockswrite_to_file,apply_diff,insert_content,search_and_replaceTesting
Example Usage
Closes #7607
Important
Introduces
edit_and_executecomposite tool for atomic file editing and command execution, with full integration and testing.edit_and_executetool totool.tsand integrates it intopresentAssistantMessage()inpresentAssistantMessage.ts.<edit>and<execute>blocks, handlingwrite_to_file,apply_diff,insert_content,search_and_replace.editAndExecuteTool.spec.tswith 100% coverage.toolParamNamesandTOOL_DISPLAY_NAMESintools.tsto include new tool.This description was created by
for 2297c7a. You can customize this summary. It will automatically update as commits are pushed.